func findTargetSumWays(nums []int, target int) int {
    /*
        left + right = sum
        right = sum - left
        left - right = target
        2left = target + sum
        left = (target + sum) / 2

        dp 数组的定义为装满容量为j的背包，可以有几种方式。
        dp[j] += dp[j-nums[i]]
        二维公式：
            dp[i][j] = dp[i-1]dp[j-nums[i]] + dp[i-1]dp[j]
    */
    var sum int
    for i:=0;i<len(nums); i++ {
        sum += nums[i]
    }
    if (target + sum) % 2 != 0 {
        return 0
    }
    if abs(target) > sum {
        return 0
    }
    packageSize := (target + sum) / 2
    dp := make([]int, packageSize+1)
    dp[0] = 1
    for i:=0; i<len(nums); i++ {
        for j:=packageSize; j>=nums[i]; j-- {
            dp[j] += dp[j-nums[i]]
        }
    }
    return dp[packageSize]
}

func max(a, b int) int {
    if a > b{
        return a
    }
    return b
}

func abs(a int) int {
    if a < 0 {
        return -a
    }
    return a
}